package com.ruoyi.tcp.entity.time;

import com.ruoyi.tcp.entity.ClientCustomerBaseEntity;
import com.ruoyi.tcp.entity.CustomerBaseEntity;
import com.ruoyi.tcp.entity.beat.ServerMessageEntity;
import com.ruoyi.tcp.util.TcpAesUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.time.ZoneOffset;
import java.util.Objects;

/**
 * @author 蒋翔 SY100242
 * @date 2024/8/8 11:23
 * @email SY100242@hnlens.com
 */
@Setter
@Getter
@ToString
public class TimeSyncCustomerEntity extends CustomerBaseEntity {

    //设备编号
    private Long deviceNumber;
    //设备序列号(RFID射频号)
    private String deviceSerializeNumber;

    @Override
    public byte[] getOtherBytes() {
        ByteBuf buffer = Unpooled.buffer();
        if(Objects.nonNull(deviceNumber)) {
            byte[] deviceNumberBytes = TcpAesUtil.longToByteArray16(deviceNumber);
            buffer.writeBytes(deviceNumberBytes);
        }
        if(StringUtils.hasText(deviceSerializeNumber)) {
            byte[] deviceSerializeNumberBytes = TcpAesUtil.hex2byte(deviceSerializeNumber);
            buffer.writeBytes(deviceSerializeNumberBytes);
        }
        return ByteBufUtil.getBytes(buffer);
    }
}
